<template>
	<view class="wrap">
		<view class="topBc"></view>
		<view class="content formWrap">
			<view class="title" style="margin-top: 0;">资产状况信息</view>
			<u-form :model="formData" ref="uForm" :rules="rules">
				<u-form-item v-if="formKeys.fundam" label="资金数额" prop="fundam" required label-width="auto" borderBottom>
					<u-input v-model="formData.fundam" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.assgro" label="资产总额" prop="assgro" required label-width="auto">
					<u-input v-model="formData.assgro" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.assgrodis" label="是否公示" prop="assgrodis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.assgrodis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.totequ" label="所有者权益合计" prop="totequ" required label-width="auto">
					<u-input v-model="formData.totequ" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.totequdis" label="是否公示" prop="totequdis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.totequdis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.liagro" label="负债总额" prop="liagro" required label-width="auto">
					<u-input v-model="formData.liagro" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.liagrodis" label="是否公示" prop="liagrodis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.liagrodis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.vendinc" label="营业总额或营业总收入" prop="vendinc" required label-width="auto">
					<u-input v-model="formData.vendinc" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.vendincdis" label="是否公示" prop="vendincdis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.vendincdis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.maibusinc" label="其中主营业收入" prop="maibusinc" required label-width="auto">
					<u-input v-model="formData.maibusinc" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.maibusincdis" label="是否公示" prop="maibusincdis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.maibusincdis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.progro" label="利润总额" prop="progro" required label-width="auto">
					<u-input v-model="formData.progro" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.progrodis" label="是否公示" prop="progrodis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.progrodis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.netinc" label="净利润" prop="netinc" required label-width="auto">
					<u-input v-model="formData.netinc" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.netincdis" label="是否公示" prop="netincdis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.netincdis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.priyeasales" label="销售额或营业收入" prop="priyeasales" required label-width="auto">
					<u-input v-model="formData.priyeasales" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view
							slot="prefix" style="transform: translateX(-12rpx);"
							@click="$util.showModal({content:'报告年度企业(机构) 及其分支机构经营主要业务和其他业务所取得的收入总额。'})"
						>
							<u-icon name="question-circle" :color="bgColor" size="34rpx"></u-icon>
						</view>
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.priyeasalesdis" label="是否公示" prop="priyeasalesdis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.priyeasalesdis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.priyeaprofit" label="盈余总额" prop="priyeaprofit" required label-width="auto">
					<u-input v-model="formData.priyeaprofit" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.priyeaprofitdis" label="是否公示" prop="priyeaprofitdis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.priyeaprofitdis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.ratgro" label="纳税总额" prop="ratgro" required label-width="auto">
					<u-input v-model="formData.ratgro" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view
							slot="prefix" style="transform: translateX(-12rpx);"
							@click="$util.showModal({content:'纳税总额是指企业全年实缴各类税金的总和，但不包括代缴的个人所得税。'})"
						>
							<u-icon name="question-circle" :color="bgColor" size="34rpx"></u-icon>
						</view>
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.ratgrodis" label="是否公示" prop="ratgrodis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.ratgrodis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.priyeasub" label="获得政府扶持资金、补助" prop="priyeasub" required label-width="auto">
					<u-input v-model="formData.priyeasub" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.priyeasubdis" label="是否公示" prop="priyeasubdis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.priyeasubdis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.priyealoan" label="金融贷款" prop="priyealoan" required label-width="auto">
					<u-input v-model="formData.priyealoan" type="number" placeholder="请输入" border="none" inputAlign="right">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.priyealoandis" label="是否公示" prop="priyealoandis" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.priyealoandis" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
			</u-form>
			
		</view>
		<view class="submitBtn_bc"></view>
		<view class="submitBtn_ubtn">
			<u-button :disabled="!$util.submitState(year,state)" @click="submit()">提交</u-button>
		</view>
	</view>
</template>

<script>
export default {
	data(){
		return{
			minFormName: 'assetinfo', //小表单类型名
			regnoInfo: this.$store.state.regnoInfo,
			year: '',
			state: '',
			bgColor: this.$config.bgColor,
			
			stateRanges: [
				{text: '是',value: '1'},
				{text: '否',value: '2'}
			],
			formData: {
				fundam: '',
				assgro: '',
				assgrodis: '',
				totequ: '',
				totequdis: '',
				liagro: '',
				liagrodis: '',
				vendinc: '',
				vendincdis: '',
				maibusinc: '',
				maibusincdis: '',
				progro: '',
				progrodis: '',
				netinc: '',
				netincdis: '',
				priyeasales: '',
				priyeasalesdis: '',
				priyeaprofit: '',
				priyeaprofitdis: '',
				ratgro: '',
				ratgrodis: '',
				priyeasub: '',
				priyeasubdis: '',
				priyealoan: '',
				priyealoandis: '',
			},
			rules: {},
			rulesAll: {
				fundam: this.$typeData.ruleData.total_moneyRule,
				assgro: this.$typeData.ruleData.total_moneyRule,
				assgrodis: this.$typeData.ruleData.disRule,
				totequ: this.$typeData.ruleData.moneyRule,
				totequdis: this.$typeData.ruleData.disRule,
				liagro: this.$typeData.ruleData.moneyRule,
				liagrodis: this.$typeData.ruleData.disRule,
				vendinc: this.$typeData.ruleData.moneyRule,
				vendincdis: this.$typeData.ruleData.disRule,
				maibusinc: this.$typeData.ruleData.moneyRule,
				maibusincdis: this.$typeData.ruleData.disRule,
				progro: this.$typeData.ruleData.moneyRule,
				progrodis: this.$typeData.ruleData.disRule,
				netinc: this.$typeData.ruleData.moneyRule,
				netincdis: this.$typeData.ruleData.disRule,
				priyeasales: this.$typeData.ruleData.moneyRule,
				priyeasalesdis: this.$typeData.ruleData.disRule,
				priyeaprofit: this.$typeData.ruleData.moneyRule,
				priyeaprofitdis: this.$typeData.ruleData.disRule,
				ratgro: this.$typeData.ruleData.moneyRule,
				ratgrodis: this.$typeData.ruleData.disRule,
				priyeasub: this.$typeData.ruleData.moneyRule,
				priyeasubdis: this.$typeData.ruleData.disRule,
				priyealoan: this.$typeData.ruleData.moneyRule,
				priyealoandis: this.$typeData.ruleData.disRule,
			},
			formKeys: {},
		}
	},
	onLoad(option) {
		this.year = option.year;
		this.state = option.state;
		this.getFormKey();
		this.getFormData();
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules)
	},
	methods:{
		// 获取小表单数据
		getFormData(){
			let url = this.$typeData.minFormUrl.get(this.minFormName);
			if(!url){
				uni.showModal({
					title: '暂无接口'
				})
				return;
			}
			this.$http.sendRequest({
				url: url,
				data: {
					regno: this.regnoInfo.regno,
					ancheyear: this.year
				}
			})
			.then(res=>{
				console.log('接口返回',res.data);
				let data = res.data;
				let keys = Object.keys(this.formKeys);
				keys.forEach(item=>{
					this.formData[item] = data[item];
				})
				console.log(789789,this.formData);
			})
			.catch(err=>{})
		},
		//获取小表单拥有字段
		getFormKey(){
			let formKeys = this.$util.getFormKeys(this.minFormName,this.regnoInfo.enttype);
			this.formKeys = formKeys;
			let keys = Object.keys(formKeys);
			keys.forEach(item=>{
				this.rules[item] = this.rulesAll[item];
			})
		},
		submit(){
			console.log(this.$refs.uForm)
			this.$refs.uForm.validate().then(res => {
				this.saveBtn();
			}).catch(errors => {
				this.$util.showToast({title:'请完善信息'})
			})
		},
		saveBtn(){
			let data = {
				regno: this.regnoInfo.regno,
				ancheyear: this.year,
			}
			data = this.$util.setSaveFormData(this.formKeys,data,this.formData);
			this.$http.sendRequest({
				url: '/annual/report/baseinfo/update-assetinfo',
				method: 'PUT',
				data: data
			})
			.then(res=>{
				this.setRecord();
			})
			.catch(err=>{})
		},
		

		
		
		
		//存一下记录
		setRecord(){
			let fillingItem = this.$minFormType.get(this.minFormName);
			this.$http.sendRequest({
				url: '/annual/report/record',
				method: 'POST',
				data: {
					regno: this.regnoInfo.regno,
					year: this.year,
					fillingItem: fillingItem,
					isImp: '0',
				},
				hideLoad: true,
			})
			.then(res=>{
				uni.navigateBack();
			})
			.catch(err=>{})
		},
		goPage(path){
			uni.navigateTo({
				url: path
			})
		},
	}
}
</script>

<style lang="less" scoped>
.wrap{
	width: 100vw;
	min-height: 100vh;
	padding-top: 16rpx;
	box-sizing: border-box;
	position: relative;
	background-color: #FFF;
	
	.topBc{
		height: 10rpx;
		background-color: #F5F6F8;
	}
}

.content{
	padding: 30rpx 36rpx;
	background-color: #FFF;
	
	.title{
		color: #E4B269;
		font-size: 36rpx;
		font-weight: bold;
		border-left: 8rpx solid #E4B269;
		line-height: 40rpx;
		padding-left: 16rpx;
		margin-bottom: 30rpx;
		margin-top: 30rpx;
	}
	
	
}
</style>